package com.jn.erp.web.api.common.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jn.erp.web.api.common.entity.InteractMessage;
import com.jn.erp.web.api.common.entity.dto.NoticeMessageDto;
import com.jn.erp.web.api.common.mapper.InteractMessageMapper;
import com.jn.erp.web.api.common.service.InteractMessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 站内消息 服务层实现
 *
 * @author jn
 */
@Service
public class InteractMessageServiceImpl extends ServiceImpl<InteractMessageMapper, InteractMessage> implements InteractMessageService {

    @Autowired
   private  InteractMessageMapper interactMessageMapper;

    @Override
    public Long renewalReminders(InteractMessage interactMessage) {
        InteractMessage message = new InteractMessage();
        message.setType("renewal");
        message.setTitle("续费提醒");
        message.setToType(2);
        message.setFromType(1);
        message.setSendTime(new Date());
        message.setAddTime(new Date());
        message.setCreator(interactMessage.getCreator());
        message.setFromId(interactMessage.getCreator());
        message.setDeleted(0);
        message.setBusinessVal(interactMessage.getOrderId());
        message.setToId(interactMessage.getToId());
        message.setContent(interactMessage.getContent());
        message.setOrgId(interactMessage.getOrgId());
        interactMessageMapper.insert(message);
        return message.getId();
    }


    @Override
    public List<NoticeMessageDto> renewalSendList(String ids) {
        if(StrUtil.isBlank(ids)){
            return null;
        }
        List<Long> collect = Arrays.asList(ids.split(",")).stream().map(i -> Long.valueOf(i)).collect(Collectors.toList());
        return baseMapper.renewalSendList(collect);
    }
}
